package com.longcai.service.impl.clyjuser;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.longcai.bean.ApiResult;
import com.longcai.entity.customer.ClyjUser;
import com.longcai.entity.customer.ClyjUserTouch;
import com.longcai.entity.customer.customerVo.ClyjUserTouchVo;
import com.longcai.mapper.clyjuser.ClyjUserMapper;
import com.longcai.mapper.clyjuser.ClyjUserTouchMapper;
import com.longcai.service.clyjuser.ClyjUserTouchService;
import com.longcai.util.LoginUser;
import com.longcai.util.UserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 邀请关系表 服务实现类
 * </p>
 *
 * @author M
 * @since 2019-04-23
 */
@Service
public class ClyjUserTouchServiceImpl extends ServiceImpl<ClyjUserTouchMapper, ClyjUserTouch> implements ClyjUserTouchService {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ClyjUserTouchMapper clyjUserTouchMapper;
    @Autowired
    private ClyjUserMapper clyjUserMapper;

    /**
     * 获取授权导购列表
     *
     * @param clyjUserTouchVo
     * @return
     */
    @Override
    public ApiResult getTouch(ClyjUserTouchVo clyjUserTouchVo) {
        try {
            //查询登录用户角色
            LoginUser loginUser = UserUtil.getLoginUser();
            //查询用户
            QueryWrapper<ClyjUser> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("user_id", loginUser.getUserId());
            ClyjUser clyjUser = this.clyjUserMapper.selectOne(queryWrapper);
            List<ClyjUserTouchVo> list = this.clyjUserTouchMapper.getTouch(loginUser.getUserId());
            for (ClyjUserTouchVo userTouchVo : list) {
                userTouchVo.setUserPId(clyjUser.getUsername());
            }
            logger.debug("查询成功");
            return ApiResult.success(list);
        } catch (Exception e) {
            logger.error("查询失败");
            e.printStackTrace();
            return ApiResult.fail("查询失败" + e.getMessage());
        }
    }
}
